home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / tnos / tnos100s / tip.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-30  |  2.6 KB  |  127 lines

  1. /* "Dumb terminal" session command for serial lines
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  *
  4.  *    Feb '91    Bill Simpson
  5.  *        rlsd control and improved dialer
  6.  */
  7. /* mods by PA0GRI */
  8. #include "global.h"
  9. #include "mbuf.h"
  10. #include "proc.h"
  11. #include "iface.h"
  12. #ifndef    UNIX
  13. #include "i8250.h"
  14. #endif
  15. #include "asy.h"
  16. #include "tty.h"
  17. #include "session.h"
  18. #include "socket.h"
  19. #include "commands.h"
  20. #include "devparam.h"
  21.  
  22.  
  23. static void tip_out __ARGS((int dev,void *n1,void *n2));
  24.  
  25.  
  26. /* Execute user telnet command */
  27. int
  28. dotip(argc,argv,p)
  29. int argc;
  30. char *argv[];
  31. void *p;
  32. {
  33.     struct session *sp;
  34.     register struct iface *ifp;
  35.     char *ifn;
  36.     int (*rawsave) __ARGS((struct iface *,struct mbuf *));
  37.     int c;
  38.  
  39.     /*Make sure this comes from console - WG7J*/
  40.     if(Curproc->input != Command->input)
  41.         return 0;
  42.  
  43.     if((ifp = if_lookup(argv[1])) == NULLIF){
  44.         tprintf(Badinterface,argv[1]);
  45.         return 1;
  46.     }
  47.     if( ifp->dev >= ASY_MAX || Asy[ifp->dev].iface != ifp ){
  48.         tprintf("Interface %s not asy port\n",argv[1]);
  49.         return 1;
  50.     }
  51.     if(ifp->raw == bitbucket){
  52.         tprintf("tip or dialer session already active on %s\n",argv[1]);
  53.         return 1;
  54.     }
  55.  
  56.     /* Allocate a session descriptor */
  57.     if((sp = newsession(argv[1],TIP,0)) == NULLSESSION){
  58.         tputs(TooManySessions);
  59.         return 1;
  60.     }
  61.  
  62.     /* Save output handler and temporarily redirect output to null */
  63.     rawsave = ifp->raw;
  64.     ifp->raw = bitbucket;
  65.  
  66.     /* Suspend the packet input driver. Note that the transmit driver
  67.      * is left running since we use it to send buffers to the line.
  68.      */
  69.     suspend(ifp->rxproc);
  70.  
  71.     /* Put tty into raw mode */
  72.     sp->ttystate.echo = 0;
  73.     sp->ttystate.edit = 0;
  74.     sockmode(sp->output,SOCK_BINARY);
  75.  
  76.     /* Now fork into two paths, one rx, one tx */
  77.     ifn = if_name( ifp, " tip out" );
  78.     sp->proc1 = newproc(ifn,256,tip_out,ifp->dev,NULL,NULL,0);
  79.     free( ifn );
  80.  
  81.     ifn = if_name( ifp, " tip in" );
  82.     chname( Curproc, ifn );
  83.     free( ifn );
  84.  
  85.     /* bring the line up (just in case) */
  86.     if ( ifp->ioctl != NULL )
  87.         (*ifp->ioctl)( ifp, PARAM_UP, TRUE, 0L );
  88.  
  89.     while((c = get_asy(ifp->dev)) != -1)
  90.         tputc(c & 0x7f);
  91.     tflush();
  92.  
  93.     killproc(sp->proc1);
  94.     sp->proc1 = NULLPROC;
  95.     ifp->raw = rawsave;
  96.     resume(ifp->rxproc);
  97.     keywait(NULLCHAR,1);
  98.     freesession(sp);
  99.     return 0;
  100. }
  101.  
  102.  
  103. /* Output process, DTE version */
  104. static void
  105. tip_out(dev,n1,n2)
  106. int dev;
  107. void *n1,*n2;
  108. {
  109.     struct mbuf *bp;
  110.     int c;
  111.  
  112.     while((c = recvchar(Curproc->input)) != EOF){
  113. #ifndef TNOS_68K
  114.         if(c == '\n')
  115. #else
  116.         if(c == '\l')
  117. #endif
  118.             c = '\r';        /* NL => CR */
  119.         bp = pushdown(NULLBUF,1);
  120.         bp->data[0] = c;
  121.         asy_send(dev,bp);
  122.         Asy[dev].iface->lastsent = secclock();
  123.     }
  124. }
  125.  
  126.  
  127.